package com.muyi.controller;

import com.muyi.pojo.entity.CategoryTag;
import com.muyi.pojo.entity.Result;
import com.muyi.service.CategoryTagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "分类-标签模块")
@Slf4j
@CrossOrigin
@RequestMapping("/categoryTag")
@RestController
public class CategoryTagController {
    @Autowired
    private CategoryTagService categoryTagService;

    /**
     * 查询分类-标签数据
     * @return
     */
    @ApiOperation(value = "查询全部分类-标签")
    @GetMapping
    public Result list(){
        log.info("查询全部分类-标签数据");
        //调用service查询分类-标签数据
        List<CategoryTag> CategoryTagList =  categoryTagService.list();
        return Result.success(CategoryTagList);
    }


    /**
     * 删除分类-标签
     * @return
     */
    @ApiOperation(value = "删除分类-标签")
    @DeleteMapping("/{category_tag_id}")
    public Result delete(@PathVariable Integer category_tag_id){
        log.info("根据category_id删除分类-标签:{}",category_tag_id);
        //调用service删除分类-标签
        categoryTagService.delete(category_tag_id);
        return Result.success();
    }


    /**
     * 新增分类-标签
     * @return
     */
    @ApiOperation(value = "新增分类-标签")
    @PostMapping
    public Result add(@RequestBody CategoryTag CategoryTag){
        log.info("新增分类-标签: {}" , CategoryTag);
        //调用service新增分类-标签
        categoryTagService.add(CategoryTag);
        return Result.success();
    }

    @ApiOperation(value = "更新分类-标签")
    @PutMapping
    public Result update(@RequestBody CategoryTag CategoryTag){
        log.info("更新分类-标签信息 : {}", CategoryTag);
        categoryTagService.update(CategoryTag);
        return Result.success();
    }

    // 根据category_id查询分类-标签
    @ApiOperation(value = "根据分类-标签id查询分类-标签")
    @GetMapping("/{category_tag_id}")
    public Result getByCategoryTagId(@PathVariable Integer category_tag_id){
        log.info("根据category_tag_id查询分类-标签, category_tag_id:{}",category_tag_id);
        CategoryTag CategoryTag = categoryTagService.getByCategoryTagId(category_tag_id);
        return Result.success(CategoryTag);
    }
}
